<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['ischecklogin']=$this->model('member')->checklogin('','','','',true);
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$shop=$this->plugin_setting('shop');
$return['shopset']=$shop;
$keywords=$this->plugin_setting('search');
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['id']);
	if (empty($orderid)) {
		exi('请选择要核销的记录!','error','jy_weishop/index/');
	}
	$getlog=$this->pdo_get('game_getlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$orderid));
	if (empty($getlog)){
		exi('核销的记录错误,无权核销','error','jy_weishop/index/');   
	}
	//商品独立核销门店：
	$prams=array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	$saler=pdo_get('jy_weishop_store_worker',$prams);
	if($getlog['merchid']){
		$merch=model('jy_merch/verify')->checkuser($_SESSION['uid'],$getlog['merchid'],'',false);
		if(!$merch['id'] && $getlog['peisong_id'] != $_SESSION['uid']) {
			if($getlog['is_daifa']){
				$is_check=1;
			}else{
				exi('该商品属于商户，您不是该商户的核销员,无权核销','error','jy_merch/verify.index/');   
			}
		}
	}
	if(!$getlog['merchid'] || $is_check){
		$store=pdo_get('jy_weishop_store',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		if (empty($saler) && !$store){
			exi('您不是该店的核销员,无权核销！','error','jy_weishop/index/');   
		}
	}
	if($getlog['status']==3){
		exi('该记录已核销，不能核销！','error','jy_weishop/index/');
	}elseif($getlog['status']==0){
		exi('该记录还未领取，不能核销！','error','jy_weishop/index/');
	}
	$getlog['createtime']=date('Y-m-d H:i:s',$getlog['createtime']);
	$getlog['reward']=json_decode($getlog['reward'],true);
	$getlog['typetitle']=$this->prizeType[$getlog['reward']['type']];
	$getlog['fee']=$getlog['fee']>0?$getlog['fee']:$getlog['reward']['jifen'];
	if($getlog['reward']['type']==1){
		$getlog['fee']=$getlog['reward']['title'];
	}
	$getlog['member']=cfc('core')->member_show($v['mid']);
	$return['post']=array(
		'orderid'=>$getlog['id'],
		'verify_code'=>$verifycode,
	);
	$return['order']=$getlog;
	set_html('title','核销奖品');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$getlogid=intval($post['orderid']);
	$this->model('verify')->game_verify($getlogid,$_SESSION['uid']);
	exi('核销成功！','','jy_weishop/index/');
	
}